package com.insuremonitor.system.service.impl;

import com.insuremonitor.common.constant.UserConstants;
import com.insuremonitor.common.core.domain.entity.MonitorUser;
import com.insuremonitor.common.utils.StringUtils;
import com.insuremonitor.system.mapper.MonitorUserMapper;
import com.insuremonitor.system.service.IMonitorUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Validator;

/**
 * 用户 业务层处理
 * 
 * @author ruoyi
 */
@Service
public class MonitorUserServiceImpl implements IMonitorUserService
{
    private static final Logger log = LoggerFactory.getLogger(MonitorUserServiceImpl.class);

    @Autowired
    private MonitorUserMapper userMapper;


    @Autowired
    protected Validator validator;


    /**
     * 通过用户名查询用户
     * 
     * @param userName 用户名
     * @return 用户对象信息
     */
    @Override
    public MonitorUser selectUserByUserName(String userName)
    {
        return userMapper.selectUserByUserName(userName);
    }




    /**
     * 校验用户名称是否唯一
     * 
     * @param user 用户信息
     * @return 结果
     */
    @Override
    public boolean checkUserNameUnique(MonitorUser user)
    {
        Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
        MonitorUser info = userMapper.checkUserNameUnique(user.getUserName());
        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }


    /**
     * 修改用户基本信息
     *
     * @param user 用户信息
     * @return 结果
     */
    @Override
    public int updateUserProfile(MonitorUser user)
    {
        return userMapper.updateMonitorUser(user);
    }



    /**
     * 重置用户密码
     *
     * @param userName 用户名
     * @param password 密码
     * @return 结果
     */
    @Override
    public int resetUserPwd(String userName, String password)
    {
        return userMapper.resetUserPwd(userName, password);
    }



}
